package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;
import java.io.IOException;

import javax.swing.Action;

import com.mrogrape.notepad.activity.action.NotepadAction;
import com.mrogrape.notepad.common.NotepadUtils;
import com.mrogrape.notepad.common.ViewUtils;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.editor.TextEditor;


public class OpenFileLocationMenuItemAction extends NotepadAction {

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public OpenFileLocationMenuItemAction(){

		super.putValue(Action.NAME, "Open File Location");
		super.putValue(Action.SHORT_DESCRIPTION, "Open the direction that contains file of current editor.");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		TextEditor editor = ViewContext.getMainFrame().getCurrentTextEditor();

		if(editor != null&&editor.getFile()!=null){

			try {
				
				NotepadUtils.openFileLocation(editor.getFile());
			} catch (IOException e) {
				
				ViewUtils.showErrorMessageDialog(editor, "I/O Exception has occured when open file location: " + editor.getFile());
			}
		}
	}
}
